package com.linwen.excise.leetcode;

/**
 * @ClassName _112路径总和
 * @Description TODO
 * @Author zero
 * @DATE 2024/4/5 1:45 AM
 * @Version 1.0
 */
public class _112路径总和 {
    public static void main(String[] args) {

    }

    public static boolean hasPathSum(TreeNode root, int sum) {
        if (root == null) {
            return false;
        }
        if (root.left == null && root.right == null) {
            return sum == root.val;
        }
        return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);
    }
}
